<?php
class HotkeyIndexAction extends AdminAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'tpl';
		$this->layout = 'admin';
	}

	public function execute()
	{
		$cid						= $this->context->get('cid');
		
		$page		= $this->getPage();
		$tmp	 	= LtObjectUtil::singleton('LtConfig')->get('pagination.pager');
		$pageSize	= $tmp['per_page'];
		if (empty($pageSize))
		{
			$pageSize 	= 20;
		}
		$num 			= $pageSize;
		$start	 		= ($page-1) * $pageSize;
		
		$con					= array();
		if(is_numeric($cid) && $cid)
		{
			$con['category_id']	= $cid;
		}
		$hotkeyService			= new HotkeyService();
		$fields					= '';
		$this->data['data'] 	= $hotkeyService->getList($con,'id DESC',$start, $num,$fields);
		
		if(!empty($this->data['data']['rows']))
		{
			$ids = array();
			foreach($this->data['data']['rows'] as $lv)
			{
				$ids[] = $lv['category_id'];
			}
			
			$categoryService = new CategoryService();
			$categories = $categoryService->getByIds($ids);
			if(!empty($categories))
			{
				$categories = C('CommonFunction')->groupData($categories,array('id'));
				foreach($this->data['data']['rows'] as &$lv)
				{
					$lv['category'] = $categories[$lv['category_id']];
				}
			}
		}
		
		$count 		= $this->data['data']['count'];
		$baseUrl 	= C('LtUrl')->generate('Hotkey', 'Index', array('cid'=>$cid,'p' => ':page'));
		
		$pagination = new LtPagination;
		$pagination->init();
		$this->data['pages'] = $pagination->pager($page, $count, $baseUrl);
		
		$categoryService			= new CategoryService();
		$this->data['menuCategory']	= $categoryService->getParentList($cid);
		
		$this->data['category_id']	= $cid;
		
		$this->data['menu']		= 'category';
		$this->data['submenu']	= 'category_index';
	}
}
